<?php
namespace Admin\Controller;

//通用Controller类
class CommonController extends \Think\Controller{
    
    public $controller = '';//当前控制器名
    
    public function _initialize(){
        header("Content-Type: text/html; charset=utf-8");
        $this->controller = CONTROLLER_NAME;
        
		//判断是否登录
		$suserRow = array();
		$suserRow = session(C('ADMIN_SESSION'));
        if(empty($suserRow)){
            $this->error('没有登录或者登录超时请重新登录后继续！',U('Admin/Index/login'));
        }
		$this->assign('suserRow',$suserRow);
    }
    
    public function index(){
        $where = array();
        if(I('get.keywords')){
            $where['name'] = array('like','%'.I('get.keywords').'%');
        }
        $dataPage = D($this->controller)->getPager($where);
        $this->assign('list',$dataPage['data']);
        $this->assign('page',$dataPage['page']);
        $this->display();
    }
    
    public function edit(){
        if(IS_POST){
            $res = D($this->controller)->saveData(I('post.'));
            $res ? die('suc') : die('err');
        }else{
            $id=I('get.id');
            if($id){
                $this->assign('vo',D($this->controller)->find($id));
            }
            $this->assign('upPageUrl',$_SERVER['HTTP_REFERER']);
            $this->display();
        }
    }

    public function del(){
        $id = intval(I('request.id'));
		if($res = D($this->controller)->delData($id)){
			die('suc');
		}else{
			die('err');
		}
    }
}